<?php

/**
 * Description of biying
 *
 * @author zhangyazhong By 2013-5-18 15:20:43
 * 
 * Info：必赢接口文件
 */
class api_biying2 extends api_base {

    private static $_host = WANLITONG_BIYING_URL;
    private static $_header = array();

    private static function creatParam($api, $param = array()) {
        ksort($param);
        $str = '';
        foreach ($param as $key => $val) {
            $str .= "{$key}={$val}&";
        }
        $param['sign'] = md5(BIYING_SIGN_KEY . "&{$str}{$api}");
        return $param;
    }

    /**
     * 返回参数大小
     * @param type $param
     * @return type
     */
    private static function paramcontent($param = array()) {
        return strlen(http_build_query($param, '', '&'));
    }

    /**
     * 获取订单信息
     * @param type $uid
     * @param type $orderID
     * @return type
     */
    public static function orderinfo($uid, $orderID) {
        $api = '/user/trade/order_detail';
        $data = array(
            'uid' => $uid,
            'orderID' => $orderID,
        );
        $param = self::creatParam($api, $data);
        self::$_header = array('Content-Length' => self::paramcontent($data));
        return self::curl(self::$_host . $api, $param, self::$_header);
    }

    /**
     * 支付成功后回调必赢地址，如果投注成功，获得订单ID
     * @param type $prebuyid
     * @param type $payid
     * @return type
     */
    public static function afterPayCallBack($prebuyid, $payid) {
        $api = '/user/trade/AfterPayCallBack';
        $data = array(
            'pblID' => $prebuyid,
            'paySn' => $payid,
        );
        $param = self::creatParam($api, $data);
        self::$_header = array('Content-Length' => self::paramcontent($data));
        return self::curl(self::$_host . $api, $param, self::$_header);
    }

    /**
     * 获取追号详情 
     * @param type $uid
     * @param type $projectID
     * @return type
     */
    public static function addNumDetail($uid, $projectID) {
        //$api = '/user/trade/my_addnum_detail';
        $api = '/user/trade/addnum_detail';
        $data = array(
            'uid' => $uid,
            'chaseID' => $projectID
        );
        $param = self::creatParam($api, $data);
        self::$_header = array('Content-Length' => self::paramcontent($data));
        return self::curl(self::$_host . $api, $param, self::$_header);
    }

}